home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9277 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  69 lines

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Schildt <- Advanced Books
  5. Date: 8 Mar 96 17:26:27 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.826305987@rscernix>
  8. References: <8BA8405.02C70020DE.uuout@sourcebbs.com> <danpop.826121528@rscernix> <4hleu9$5ah@solutions.solon.com> <danpop.826238706@rscernix> <4ho3m3$iov@solutions.solon.com>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4ho3m3$iov@solutions.solon.com> seebs@solutions.solon.com (Peter Seebach) writes:
  13.  
  14. >In article <danpop.826238706@rscernix>, Dan Pop <danpop@mail.cern.ch> wrote:
  15. >>In <4hleu9$5ah@solutions.solon.com> seebs@solutions.solon.com (Peter Seebach) writes:
  16. >>>I consider a bug subtle if the code is likely to work correctly most of the
  17. >>>time.
  18. >
  19. >>So, you consider "void main" and calling malloc without a declaration in
  20. >>scope subtle bugs :-)
  21. >
  22. >Yup.  They are not obvious to a casual programmer who hasn't specifically
  23. >been warned about them.  The latter especially; if you're looking at
  24. >code in the middle of a 500+ line module, how often do you remember to
  25. >check for relevant headers?  :)
  26.  
  27. My compiler _will_ warn about illegal integer to pointer conversion
  28. and I NEVER ignore such a warning.  Moreover, even the silly cast in front
  29. of malloc won't prevent gcc from telling me that something silly is
  30. happening:
  31.  
  32.     ues5:~/tmp 30> cat test.c
  33.     main()
  34.     {
  35.     char *p = (char *)malloc(100);
  36.     }
  37.     ues5:~/tmp 31> gcc test.c
  38.     test.c: In function `main':
  39.     test.c:3: warning: cast to pointer from integer of different size
  40.  
  41. But this is because I have the "privilege" of using a system where 
  42. pointers and int's have different sizes.  It's amazing how much new free
  43. software has to be fixed, even today, three years after the Alpha boxes
  44. have hit the market.
  45.  
  46. >The same book, at one point, declares
  47. >    char *buf[128];
  48. >and passes the buffer to something like fgets().  
  49.  
  50. I'd stay away from any book which has untested examples.  We are all
  51. human and we all make mistakes, but any serious author will, at least,
  52. compile his examples to be sure they're correct and will introduce the
  53. source code directly into the "manuscript", to be sure that no typo could
  54. find its way in.  Many authors even document this practice, somewhere in
  55. the preface (e.g. the last phrase on page ix of K&R2).
  56.  
  57. >I consider this much more
  58. >serious; it is likely to slip into real code, and will not even produce a
  59. >warning on certain oft-used and broken systems, like Sun's.
  60.  
  61. Anybody using cc (without lint) on SunOS gets exactly what s/he deserves.
  62.  
  63. Dan
  64. --
  65. Dan Pop
  66. CERN, CN Division
  67. Email: danpop@mail.cern.ch 
  68. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  69.